package com.ruoyi.wx.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wx.domain.AttendanceRecord;
import com.ruoyi.wx.domain.vo.AttendanceRecordVo1;
import com.ruoyi.wx.service.serviceImpl.AttendanceRecordServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/attendance")
public class wxAttendanceRecordController {

    @Autowired
    @Qualifier("wxAttendanceRecordService")
    private AttendanceRecordServiceImpl attendanceRecordService;

    @GetMapping("/attendanceRecord")
    public AjaxResult attendanceRecord(long userId , String recordDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date time;
        try {
            time = sdf.parse(recordDate);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        AttendanceRecord attendance = new AttendanceRecord();
        attendance.setUserId(userId);
        attendance.setRecordDate(time);
        System.out.println(attendance);
        return AjaxResult.success((Object) attendanceRecordService.selectAttendanceByRecordData(attendance));
    }


    @PostMapping("/addAttendanceRecord")
    public AjaxResult addAttendanceRecord(@RequestBody AttendanceRecordVo1 attendanceRecord){
        int i = attendanceRecordService.insertAttendanceRecord(attendanceRecord);
        return AjaxResult.success(i);
    }

}
